home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Toolkit / Songbird 0.1 / Songbird_0_1_0.exe / chrome / content / smilScript.js < prev    next >
Text File  |  2005-11-26  |  40KB  |  1,080 lines

  1. /*
  2. SMILScript: A partial SMIL implementation in script, to provide transitional functionality for Firefox, Batik, and other SVG Viewers without SMIL animation. Many thanks to Jonathan Watt and Jeff Rafter for advice.
  3.  
  4. Author:  Doug Schepers [doug.schepers@vectoreal.com]
  5. Date:    Friday, November 04, 2005
  6. Version: 0.1
  7.  
  8. This software is Copyright (c) Vectoreal (tm) and Doug Schepers.
  9. All rights reserved.
  10.  
  11. The Artistic License
  12. [http://www.opensource.org/licenses/artistic-license.php]
  13.  
  14. Preamble
  15.  
  16. The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications.
  17.  
  18. Definitions:
  19.  
  20.     * "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification.
  21.     * "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder.
  22.     * "Copyright Holder" is whoever is named in the copyright or copyrights for the package.
  23.     * "You" is you, if you're thinking about copying or distributing this Package.
  24.     * "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.)
  25.     * "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it.
  26.  
  27. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers.
  28.  
  29. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version.
  30.  
  31. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following:
  32.  
  33.     a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package.
  34.  
  35.     b) use the modified Package only within your corporation or organization.
  36.  
  37.     c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version.
  38.  
  39.     d) make other distribution arrangements with the Copyright Holder.
  40.  
  41. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following:
  42.  
  43.     a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version.
  44.  
  45.     b) accompany the distribution with the machine-readable source of the Package with your modifications.
  46.  
  47.     c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version.
  48.  
  49.     d) make other distribution arrangements with the Copyright Holder.
  50.  
  51. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own.
  52.  
  53. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package.
  54.  
  55. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package.
  56.  
  57. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission.
  58.  
  59. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  60.  
  61. The End
  62.  
  63. */
  64. var SVGDocument = null;
  65. var SVGRoot = null;
  66. var svgns = 'http://www.w3.org/2000/svg';
  67. var xlinkns = 'http://www.w3.org/1999/xlink';
  68.  
  69. var Event = null;
  70. var Smil  = null;
  71.  
  72. var textOutput = null;
  73.  
  74. function InitSMIL(evt)
  75. {
  76.    SVGDocument = evt.target.ownerDocument;
  77.    SVGRoot     = SVGDocument.documentElement;
  78.    textOutput = SVGDocument.getElementById('textOutput');
  79.  
  80.    try
  81.    {
  82.       if ( -1 != getSVGViewerVersion().indexOf('ASV') )
  83.       {
  84.          return;
  85.       }
  86.    }
  87.    catch(er) {}
  88.  
  89.    Event       = new EventObj();
  90.    Smil        = new SMILObj();
  91.  
  92.    Smil.getSmilElements();
  93. };
  94.  
  95.  
  96. function EventObj(){};
  97. EventObj.prototype = {};
  98.  
  99. EventObj.prototype.eventHandler = function( evt )
  100. {
  101.    var triggerEl = evt.target;
  102.    var smilArray = Smil.idArray[ triggerEl.id ];
  103.  
  104.    for ( var i = 0, iLen = smilArray.length; iLen > i; i++ )
  105.    {
  106.       var eachObj = smilArray[i];
  107.       if ( evt.type == eachObj.begin
  108.        || -1 != eachObj.begin.indexOf( evt.type )
  109.        || -1 != eachObj.begin.indexOf( triggerEl.id + '.' + evt.type ) )
  110.       {
  111.          var eventValue = eachObj.begin.split('+');
  112.          if ( 1 == eventValue.length )
  113.          {
  114.             Smil[ eachObj.name ]( eachObj.index );
  115.          }
  116.          else
  117.          {
  118.             var eventTimeout = Smil.normalizeTime( eventValue[1] );
  119.  
  120.             var smilCall = 'Smil.dispatch( ' + eachObj.index + ' )';
  121.             window.setTimeout( smilCall, eventTimeout );
  122.          }
  123.       }
  124.    }
  125. };
  126.  
  127.  
  128. function SMILObj()
  129. {
  130.    this.idArray       = [];
  131.    this.objArray      = [];
  132.    this.elementArray  = [];
  133.    this.triggerArray  = [];
  134.    this.timeline      = null;
  135. }
  136. SMILObj.prototype = {};
  137.  
  138. SMILObj.prototype.props = function( index, element, id, name, parentEl, targetEl, href, begin, end, attributeName, attributeType, type, from, to, by, values, path, pathEl, begin, end, dur, fill, repeatCount, initialValue )
  139. {
  140.    this.index              = index;
  141.    this.element            = element;
  142.    this.id                 = id;
  143.    this.name               = name;
  144.    this.parentEl           = parentEl;
  145.    this.targetEl           = targetEl;
  146.    this.href               = href;
  147.    this.begin              = begin;
  148.    this.end                = end;
  149.    this.attributeName      = attributeName;
  150.    this.attributeType      = attributeType;
  151.    this.type               = type;
  152.    this.from               = from;
  153.    this.to                 = to;
  154.    this.by                 = by;
  155.    this.values             = values;
  156.    this.path               = path;
  157.    this.pathEl             = pathEl;
  158.    this.begin              = begin;
  159.    this.end                = end;
  160.    this.dur                = dur;
  161.    this.fill               = fill;
  162.    this.repeatCount        = repeatCount;
  163.    this.repeatIndex        = Number(repeatCount);
  164.    this.initialValue       = Number(initialValue);
  165.    this.currentValue       = Number(initialValue);
  166.    this.increment          = null;
  167.    this.interval           = null;
  168.    this.initialValueArray  = [];
  169.    this.currentValueArray  = [];
  170.    this.finalValueArray    = [];
  171.    this.incrementArray     = [];
  172.    this.syncArray          = [];
  173. };
  174.  
  175. SMILObj.prototype.getSmilElements = function()
  176. {
  177.    var smilElementsArray = ['set', 'animate', 'animateColor', 'animateMotion', 'animateTransform'];
  178.    for ( var i = 0, iLen = smilElementsArray.length; iLen > i; i++ )
  179.    {
  180.       var eachElementType = smilElementsArray[i];
  181.  
  182.       var allElements = SVGDocument.getElementsByTagNameNS(svgns, eachElementType);
  183.       for ( var s = 0, sLen = allElements.length; sLen > s; s++ )
  184.       {
  185.          var eachElement = allElements.item(s);
  186.          var smilObj = this.registerElement( eachElement );
  187.       }
  188.    }
  189. };
  190.  
  191. SMILObj.prototype.registerElement = function( element )
  192. {
  193.    var id            = element.id;
  194.    var name          = element.localName;
  195.    var parentEl      = element.parentNode;
  196.    var targetEl      = element.parentNode;
  197.    var href          = element.getAttributeNS(xlinkns, 'href');
  198.    var begin         = element.getAttributeNS(null, 'begin');
  199.    var end           = element.getAttributeNS(null, 'end');
  200.    var attributeName = element.getAttributeNS(null, 'attributeName');
  201.    var attributeType = element.getAttributeNS(null, 'attributeType');
  202.    var type          = element.getAttributeNS(null, 'type');
  203.    var from          = element.getAttributeNS(null, 'from');
  204.    var to            = element.getAttributeNS(null, 'to');
  205.    var by            = element.getAttributeNS(null, 'by');
  206.    var values        = element.getAttributeNS(null, 'values');
  207.    var path          = element.getAttributeNS(null, 'path');
  208.    var begin         = element.getAttributeNS(null, 'begin');
  209.    var end           = element.getAttributeNS(null, 'end');
  210.    var dur           = element.getAttributeNS(null, 'dur');
  211.    var fill          = element.getAttributeNS(null, 'fill');
  212.    var repeatCount   = element.getAttributeNS(null, 'repeatCount');
  213.  
  214.    if ( href )
  215.    {
  216.       targetEl = GetElementByAtt( 'id', href.replace('#', '') );
  217.    }
  218.  
  219.    if ( 'CSS' == attributeType )
  220.    {
  221.       var initialValue = targetEl.style.getPropertyValue( attributeName );
  222.    }
  223.    else
  224.    {
  225.       var initialValue = targetEl.getAttributeNS( null, attributeName );
  226.    }
  227.  
  228.    if ( !from )
  229.    {
  230.       if ( initialValue )
  231.       {
  232.          from = initialValue;
  233.       }
  234.       else if ( propDefaults[attributeName] )
  235.       {
  236.          from = propDefaults[attributeName];
  237.       }
  238.       else
  239.       {
  240.          from = 0;
  241.       }
  242.    }
  243.  
  244.    if ( by && !to )
  245.    {
  246.       to = by;
  247.    }
  248.  
  249.    var pathEl = null;
  250.    if ( 'animateMotion' == name )
  251.    {
  252.       if ( !path )
  253.       {
  254.          var mpaths = element.getElementsByTagNameNS(svgns, 'mpath');
  255.          var mpath = mpaths.item(0);
  256.          if ( mpath )
  257.          {
  258.             var pathHref = mpath.getAttributeNS(xlinkns, 'href');
  259.             pathEl = GetElementByAtt( 'id', pathHref.replace('#', '')  );
  260.             path = pathEl.getAttributeNS(null, 'd');
  261.          }
  262.       }
  263.       else
  264.       {
  265.          pathEl = SVGDocument.createElementNS(svgns, 'path');
  266.          pathEl.setAttributeNS(null, 'd', path);
  267.          pathEl.setAttributeNS(null, 'display', 'none');
  268.          element.parentNode.appendChild( pathEl );
  269.       }
  270.    }
  271.  
  272.    begin = begin.replace(' ', '');
  273.    to = to.replace(' ', '');
  274.  
  275.    var index = this.objArray.length;
  276.  
  277.    var smilObj = new this.props( index, element, id, name, parentEl, targetEl, href, begin, end, attributeName, attributeType, type, from, to, by, values, path, pathEl, begin, end, dur, fill, repeatCount, initialValue );
  278.  
  279.    this.objArray.push( smilObj );
  280.    this.elementArray[ element ] = index;
  281.  
  282.    smilObj.syncArray['begin'] = [];
  283.    smilObj.syncArray['end'] = [];
  284.  
  285.    this.processBeginTriggers( element, smilObj );
  286.  
  287.    var beginArray = begin.split(';');
  288.    for ( var i = 0, iLen = beginArray.length; iLen > i; i++ )
  289.    {
  290.       var eachBegin = beginArray[i];
  291.       var triggerElement = parentEl;
  292.  
  293.       var eventTimeout = Smil.normalizeTime( eachBegin );
  294.       if ( !isNaN(eventTimeout) )
  295.       {
  296.          var smilCall = 'Smil.dispatch( ' + smilObj.index + ' )';
  297.          window.setTimeout( smilCall, eventTimeout );
  298.       }
  299.       else
  300.       {
  301.          var triggerValue = eachBegin.split('+');
  302.          var triggerArray = triggerValue[0].split('.');
  303.          var triggerEvent = triggerArray[0];
  304.          if ( 1 < triggerArray.length )
  305.          {
  306.             var triggerId = triggerArray[0];
  307.             triggerElement = GetElementByAtt( 'id', triggerId  );
  308.  
  309.             triggerEvent= triggerArray[1];
  310.          }
  311.  
  312.          if ( 'begin' == triggerEvent || 'end' == triggerEvent )
  313.          {
  314.  
  315.             this.addTriggerToElement( triggerElement, triggerId, triggerEvent, smilObj, eachBegin );
  316.          }
  317.          else if ( triggerElement )
  318.          {
  319.             if ( this.idArray[ triggerElement.id ] )
  320.             {
  321.                this.idArray[ triggerElement.id ].push( smilObj );
  322.             }
  323.             else
  324.             {
  325.                this.idArray[ triggerElement.id ] = [ smilObj ];
  326.             }
  327.  
  328.             triggerElement.addEventListener(triggerEvent, Event.eventHandler, false);
  329.          }
  330.       }
  331.    }
  332.  
  333.    return smilObj;
  334. };
  335.  
  336. SMILObj.prototype.getObjByElement = function( element )
  337. {
  338.    var obj = null;
  339.    for ( var i = 0, iLen = this.objArray.length; iLen > i; i++ )
  340.    {
  341.       var eachObj = this.objArray[i];
  342.       if ( element == eachObj.element )
  343.       {
  344.          obj = eachObj;
  345.       }
  346.    }
  347.    return obj;
  348. };
  349.  
  350. SMILObj.prototype.addTriggerToElement = function( triggerEl, triggerId, triggerEvent, smilObj, begin )
  351. {
  352.    if ( 'prev' == triggerId )
  353.    {
  354.       triggerEl = smilObj.element.previousSibling;
  355.       while( triggerEl && 1 != triggerEl.nodeType )
  356.       {
  357.          triggerEl = triggerEl.previousSibling;
  358.       }
  359.    }
  360.  
  361.    var triggerObj = this.getObjByElement( triggerEl );
  362.    if ( triggerObj )
  363.    {
  364.       this.processEachBegin( triggerObj, smilObj, begin );
  365.    }
  366.    else
  367.    {
  368.       var trigger = this.getTriggerByElement( triggerEl );
  369.       if ( !trigger )
  370.       {
  371.          trigger = new this.triggerHash( triggerEl );
  372.          this.triggerArray.push( trigger );
  373.       }
  374.       trigger.triggerTargets.push( smilObj );
  375.    }
  376. };
  377.  
  378. SMILObj.prototype.triggerHash = function( element )
  379. {
  380.    this.element        = element;
  381.    this.triggerTargets = [];
  382. };
  383.  
  384. SMILObj.prototype.getTriggerByElement = function( element )
  385. {
  386.    var obj = null;
  387.    for ( var i = 0, iLen = this.triggerArray.length; iLen > i; i++ )
  388.    {
  389.       var eachTrigger = this.triggerArray[i];
  390.       if ( element == eachTrigger.element )
  391.       {
  392.          obj = eachTrigger;
  393.       }
  394.    }
  395.    return obj;
  396. };
  397.  
  398. SMILObj.prototype.processBeginTriggers = function( triggerEl, triggerObj )
  399. {
  400.    var trigger = this.getTriggerByElement( triggerEl );
  401.    if ( trigger )
  402.    {
  403.       var triggerArray = trigger.triggerTargets;
  404.       for ( var i = 0, iLen = triggerArray.length; iLen > i; i++ )
  405.       {
  406.          var eachObj = triggerArray[i];
  407.          var beginArray = eachObj.begin.split(';');
  408.          for ( var b = 0, bLen = beginArray.length; bLen > b; b++ )
  409.          {
  410.             var eachBegin = beginArray[b];
  411.             this.processEachBegin( triggerObj, eachObj, eachBegin );
  412.          }
  413.       }
  414.    }
  415. };
  416.  
  417. SMILObj.prototype.syncObj = function( objIndex, triggerTime )
  418. {
  419.    this.objIndex    = objIndex;
  420.    this.triggerTime = triggerTime;
  421. };
  422.  
  423. SMILObj.prototype.processEachBegin = function( triggerObj, targetObj, begin )
  424. {
  425.    var triggerValue = begin.split('+');
  426.    var triggerArray = triggerValue[0].split('.');
  427.    var triggerEvent = triggerArray[0];
  428.    if ( 2 == triggerArray.length )
  429.    {
  430.       triggerEvent= triggerArray[1];
  431.    }
  432.    var triggerTime = this.normalizeTime( triggerValue[1] );
  433.  
  434.    var sync = new this.syncObj( targetObj.index, triggerTime );
  435.  
  436.    triggerObj.syncArray[ triggerEvent ].push( sync );
  437. };
  438.  
  439. SMILObj.prototype.dispatch = function( objId )
  440. {
  441.    var obj = this.objArray[ objId ];
  442.    this[ obj.name ]( objId );
  443.  
  444.    this.dispatchSyncs( obj.syncArray[ 'begin' ] );
  445. };
  446.  
  447. SMILObj.prototype.set = function( objId )
  448. {
  449.    var obj = this.objArray[ objId ];
  450.    var targetEl = obj.targetEl;
  451.    this.resetRepeat( obj );
  452.  
  453.    if ( 'CSS' == obj.attributeType )
  454.    {
  455.       targetEl.style.setProperty(obj.attributeName, obj.to, '');
  456.    }
  457.    else
  458.    {
  459.       targetEl.setAttributeNS(null, obj.attributeName, obj.to);
  460.    }
  461. };
  462.  
  463. SMILObj.prototype.animate = function( objId )
  464. {
  465.    var obj = this.objArray[ objId ];
  466.    this.resetRepeat( obj );
  467.  
  468.    var duration = (Smil.normalizeTime( obj.dur ) / 1000) * 70;
  469.    var from = Number( obj.from );
  470.  
  471.    var to = Number( obj.to );
  472.  
  473.    var diff = Math.max(from, to) - Math.min(from, to);
  474.    obj.increment = Math.round((diff/duration) * 1000 ) / 1000;
  475.  
  476.    if ( to < from )
  477.    {
  478.       obj.increment *= -1;
  479.    }
  480.  
  481.    var smilCall = 'Smil.setRepeat( ' + objId + ' )';
  482.    window.setTimeout( smilCall, 10 );
  483. };
  484.  
  485. SMILObj.prototype.animateMotion = function( objId )
  486. {
  487.    var obj = this.objArray[ objId ];
  488.    this.resetRepeat( obj );
  489.  
  490.    if ( obj.path )
  491.    {
  492.       try
  493.       {
  494.          var point = obj.pathEl.getPointAtLength( 0 );
  495.          var distance = obj.pathEl.getTotalLength();
  496.          var duration = (Smil.normalizeTime( obj.dur ) / 1000) * 70;
  497.  
  498.          obj.increment = distance/duration;
  499.          obj.currentValue = 0;
  500.  
  501.          var smilCall = 'Smil.incrementPosition( ' + objId + ' )';
  502.          window.setTimeout( smilCall, 10 );
  503.       }
  504.       catch(er){}
  505.    }
  506.    else if ( obj.to )
  507.    {
  508.       var duration = (Smil.normalizeTime( obj.dur ) / 1000) * 70;
  509.  
  510.       obj.finalValueArray = obj.to.split( ',' );
  511.  
  512.       obj.initialValueArray = [0];
  513.       if ( 2 == obj.finalValueArray.length )
  514.       {
  515.          obj.initialValueArray.push(0);
  516.       }
  517.       obj.currentValueArray = [];
  518.       obj.currentValueArray = obj.initialValueArray.concat();
  519.  
  520.  
  521.       for ( var i = 0, iLen = obj.initialValueArray.length; iLen > i; i++ )
  522.       {
  523.          var from = Number( obj.initialValueArray[i] );
  524.  
  525.          var to = Number( obj.finalValueArray[i] );
  526.  
  527.          var diff = Math.max(from, to) - Math.min(from, to);
  528.          obj.incrementArray[i] = Math.round((diff/duration) * 1000 ) / 1000;
  529.  
  530.          if ( to < from )
  531.          {
  532.             obj.incrementArray[i] *= -1;
  533.          }
  534.       }
  535.  
  536.       var smilCall = 'Smil.setRepeatArray( ' + objId + ' )';
  537.       window.setTimeout( smilCall, 10 );
  538.    }
  539.    else { }
  540. };
  541.  
  542. SMILObj.prototype.animateTransform = function( objId )
  543. {
  544.    var obj = this.objArray[ objId ];
  545.    this.resetRepeat( obj );
  546.  
  547.    var duration = (Smil.normalizeTime( obj.dur ) / 1000) * 70;
  548.  
  549.    obj.initialValueArray = this.splitTransform( obj.from );
  550.    obj.currentValueArray = [];
  551.    obj.currentValueArray = obj.initialValueArray.concat();
  552.    obj.finalValueArray = this.splitTransform( obj.to );
  553.  
  554.    for ( var i = 0, iLen = obj.initialValueArray.length; iLen > i; i++ )
  555.    {
  556.       var from = Number( obj.initialValueArray[i] );
  557.  
  558.       var to = Number( obj.finalValueArray[i] );
  559.  
  560.       var diff = Math.max(from, to) - Math.min(from, to);
  561.       obj.incrementArray[i] = Math.round((diff/duration) * 1000 ) / 1000;
  562.  
  563.       if ( to < from )
  564.       {
  565.          obj.incrementArray[i] *= -1;
  566.       }
  567.    }
  568.  
  569.    var smilCall = 'Smil.setRepeatArray( ' + objId + ' )';
  570.    window.setTimeout( smilCall, 10 );
  571. };
  572.  
  573. SMILObj.prototype.animateColor = function( objId )
  574. {
  575.    var obj = this.objArray[ objId ];
  576.    this.resetRepeat( obj );
  577.  
  578.    if ( -1 != obj.from.indexOf('#') )
  579.    {
  580.       var hex = colorList.normalizeHex( obj.from );
  581.       var rgb = colorList.getRgbByHex( hex );
  582.    }
  583.    else if ( -1 != obj.from.indexOf('rgb') )
  584.    {
  585.       var rgb = colorList.normalizeRgb( obj.from );
  586.    }
  587.    else
  588.    {
  589.       var rgb = colorList.getRgbByName( obj.from );
  590.    }
  591.  
  592.    obj.initialValueArray = colorList.splitRgb( rgb );
  593.    obj.currentValueArray = [];
  594.    obj.currentValueArray = obj.initialValueArray.concat();
  595.  
  596.    if ( -1 != obj.to.indexOf('#') )
  597.    {
  598.       var hex = colorList.normalizeHex( obj.to );
  599.       var rgb = colorList.getRgbByHex( hex );
  600.    }
  601.    else if ( -1 != obj.to.indexOf('rgb') )
  602.    {
  603.       var rgb = colorList.normalizeRgb( obj.to );
  604.    }
  605.    else
  606.    {
  607.       var rgb = colorList.getRgbByName( obj.to );
  608.    }
  609.  
  610.    obj.finalValueArray = colorList.splitRgb( rgb );
  611.  
  612.  
  613.    var duration = (Smil.normalizeTime( obj.dur ) / 1000) * 70;
  614.  
  615.    for ( var i = 0, iLen = obj.initialValueArray.length; iLen > i; i++ )
  616.    {
  617.       var from = Number( obj.initialValueArray[i] );
  618.  
  619.       var to = Number( obj.finalValueArray[i] );
  620.  
  621.       var diff = Math.max(from, to) - Math.min(from, to);
  622.       obj.incrementArray[i] = Math.round((diff/duration) * 1000 ) / 1000;
  623.  
  624.       if ( to < from )
  625.       {
  626.          obj.incrementArray[i] *= -1;
  627.       }
  628.    }
  629.  
  630.    var smilCall = 'Smil.setRepeatArray( ' + objId + ' )';
  631.    window.setTimeout( smilCall, 10 );
  632. };
  633.  
  634. SMILObj.prototype.setRepeat = function( objId )
  635. {
  636.    var obj = this.objArray[ objId ];
  637.    var targetEl = obj.targetEl;
  638.  
  639.    obj.currentValue = Math.round((Number(obj.currentValue) * 1000) + (Number(obj.increment) * 1000)) / 1000;
  640.  
  641.    if ( (0 > obj.increment && obj.to >= obj.currentValue)
  642.       || (0 < obj.increment && obj.to <= obj.currentValue))
  643.    {
  644.       obj.repeatIndex--;
  645.  
  646.       if ( 0 < obj.repeatIndex || 'freeze' != obj.fill )
  647.       {
  648.          obj.currentValue = obj.from;
  649.       }
  650.    }
  651.  
  652.    if ( 'CSS' == obj.attributeType )
  653.    {
  654.       targetEl.style.setProperty(obj.attributeName, obj.currentValue, '');
  655.    }
  656.    else
  657.    {
  658.       targetEl.setAttributeNS(null, obj.attributeName, obj.currentValue);
  659.    }
  660.  
  661.    if ( 'indefinite' == obj.repeatCount )
  662.    {
  663.       window.setTimeout( 'Smil.setRepeat( ' + objId + ' )', 10 );
  664.    }
  665.    else if ( 0 < obj.repeatIndex )
  666.    {
  667.       window.setTimeout( 'Smil.setRepeat( ' + objId + ' )', 10 );
  668.    }
  669.    else
  670.    {
  671.       this.dispatchSyncs( obj.syncArray[ 'end' ] );
  672.    }
  673. };
  674.  
  675. SMILObj.prototype.setRepeatArray = function( objId )
  676. {
  677.    var obj = this.objArray[ objId ];
  678.    var targetEl = obj.targetEl;
  679.  
  680.    var completeArray = [];
  681.  
  682.    for ( var i = 0, iLen = obj.currentValueArray.length; iLen > i; i++ )
  683.    {
  684.       var eachItem = obj.currentValueArray[i];
  685.       if ( 0 != obj.incrementArray[i] && !isNaN(eachItem) )
  686.       {
  687.          obj.currentValueArray[i] = Math.round((Number(obj.currentValueArray[i]) * 1000) + (Number(obj.incrementArray[i]) * 1000)) / 1000;
  688.          if ( 'animateColor' == obj.name )
  689.          {
  690.             obj.currentValueArray[i] = Math.round(obj.currentValueArray[i]);
  691.          }
  692.  
  693.          completeArray[i] = false;
  694.          if ( (0 >= obj.incrementArray[i] && obj.finalValueArray[i] >= obj.currentValueArray[i])
  695.             || (0 <= obj.incrementArray[i] && obj.finalValueArray[i] <= obj.currentValueArray[i]))
  696.          {
  697.             completeArray[i] = true;
  698.          }
  699.       }
  700.    }
  701.  
  702.    var completeString = completeArray.join(',');
  703.    if ( -1 == completeString.indexOf('false') )
  704.    {
  705.       obj.repeatIndex--;
  706.  
  707.       if ( 0 < obj.repeatIndex || 'freeze' != obj.fill )
  708.       {
  709.          obj.currentValueArray = [];
  710.          obj.currentValueArray = obj.initialValueArray.concat();
  711.       }
  712.    }
  713.  
  714.    var attName = obj.attributeName;
  715.    var newValue = obj.currentValueArray.join(' ');
  716.    if ( 'animateColor' == obj.name )
  717.    {
  718.       newValue = 'rgb(' + obj.currentValueArray.join(',') + ')';
  719.    }
  720.    else if ( 'animateMotion' == obj.name )
  721.    {
  722.       attName = 'transform';
  723.       newValue = 'translate(' + obj.currentValueArray.join(',') + ')';
  724.    }
  725.    else if ( 'animateTransform' == obj.name )
  726.    {
  727.       newValue = obj.type + '(' + obj.currentValueArray.join(',') + ')';
  728.    }
  729.  
  730.    if ( 'CSS' == obj.attributeType )
  731.    {
  732.       targetEl.style.setProperty(attName, newValue, '');
  733.    }
  734.    else
  735.    {
  736.       targetEl.setAttributeNS(null, attName, newValue);
  737.    }
  738.  
  739.    if ( 'indefinite' == obj.repeatCount )
  740.    {
  741.       window.setTimeout( 'Smil.setRepeatArray( ' + objId + ' )', 10 );
  742.    }
  743.    else if ( 0 < obj.repeatIndex )
  744.    {
  745.       window.setTimeout( 'Smil.setRepeatArray( ' + objId + ' )', 10 );
  746.    }
  747.    else
  748.    {
  749.       this.dispatchSyncs( obj.syncArray[ 'end' ] );
  750.    }
  751. };
  752.  
  753. SMILObj.prototype.incrementPosition = function( objId )
  754. {
  755.    var obj = this.objArray[ objId ];
  756.    var targetEl = obj.targetEl;
  757.  
  758.    var pos = obj.pathEl.getPointAtLength( obj.currentValue );
  759.  
  760.    obj.currentValue += obj.increment;
  761.  
  762.    if ( obj.pathEl.getTotalLength() < obj.currentValue )
  763.    {
  764.       obj.currentValue = 0;
  765.       obj.repeatIndex--;
  766.    }
  767.  
  768.    targetEl.setAttributeNS(null, 'transform', 'translate(' + pos.x + ',' + pos.y + ')' );
  769.  
  770.    if ( 'indefinite' == obj.repeatCount )
  771.    {
  772.       window.setTimeout( 'Smil.incrementPosition( ' + objId + ' )', 10 );
  773.    }
  774.    else if ( 0 < obj.repeatIndex )
  775.    {
  776.       window.setTimeout( 'Smil.incrementPosition( ' + objId + ' )', 10 );
  777.    }
  778.    else
  779.    {
  780.       this.dispatchSyncs( obj.syncArray[ 'end' ] );
  781.    }
  782. };
  783.  
  784. SMILObj.prototype.dispatchSyncs = function( syncArray )
  785. {
  786.    for ( var i = 0, iLen = syncArray.length; iLen > i; i++ )
  787.    {
  788.       var eachSync = syncArray[i];
  789.  
  790.       var eventTimeout = eachSync.triggerTime;
  791.  
  792.       var smilCall = 'Smil.dispatch( ' + eachSync.objIndex + ' )';
  793.       window.setTimeout( smilCall, eventTimeout );
  794.    }
  795.  
  796. };
  797.  
  798. SMILObj.prototype.splitTransform = function( value )
  799. {
  800.    value = value.replace(' ', '');
  801.    var valueSplit = value.split(/(,)/);
  802.    var newValueSplit = [];
  803.    for ( var i = 0, iLen = valueSplit.length; iLen > i; i++ )
  804.    {
  805.       var eachItem = Number(valueSplit[i]);
  806.       if ( !isNaN(eachItem) )
  807.       {
  808.          newValueSplit.push( eachItem );
  809.       }
  810.  
  811.    }
  812.  
  813.    return newValueSplit;
  814. };
  815.  
  816. SMILObj.prototype.normalizeTime = function( time )
  817. {
  818.    if ( 'indefinite' == time )
  819.    {
  820.       return time;
  821.    }
  822.  
  823.    if ( !time )
  824.    {
  825.       return 0;
  826.    }
  827.  
  828.    var milliseconds = 0;
  829.    if ( -1 != time.indexOf('ms') )
  830.    {
  831.       milliseconds = Number( time.replace('ms', '') );
  832.    }
  833.    else if ( -1 != time.indexOf('s') )
  834.    {
  835.       milliseconds = Number( time.replace('s', '') ) * 1000;
  836.    }
  837.    else if ( -1 != time.indexOf('min') )
  838.    {
  839.       milliseconds = Number( time.replace('min', '') ) * 60000;
  840.    }
  841.    else if ( -1 != time.indexOf('h') )
  842.    {
  843.       milliseconds = Number( time.replace('h', '') ) * 3600000;
  844.    }
  845.    else
  846.    {
  847.       var timeArray = time.split(':');
  848.       var hours = 0;
  849.       var minutes = 0;
  850.       var seconds = 0;
  851.       if ( 3 == timeArray.length )
  852.       {
  853.          hours = Number( timeArray[0] ) * 3600000;
  854.          minutes = Number( timeArray[1] ) * 60000;
  855.          seconds = Number( timeArray[2] ) * 1000;
  856.       }
  857.       else if ( 2 == timeArray.length )
  858.       {
  859.          minutes = Number( timeArray[0] ) * 60000;
  860.          seconds = Number( timeArray[1] ) * 1000;
  861.       }
  862.       else
  863.       {
  864.          seconds = Number( timeArray[0] ) * 1000;
  865.       }
  866.       milliseconds = hours + minutes + seconds;
  867.    }
  868.  
  869.    return milliseconds;
  870. };
  871.  
  872. SMILObj.prototype.resetRepeat = function( obj )
  873. {
  874.    if ( 'indefinite' != obj.repeatCount )
  875.    {
  876.       obj.repeatIndex = Number(obj.repeatCount);
  877.    }
  878. };
  879.  
  880.  
  881. var propDefaults = [];
  882. propDefaults['alignment-baseline'] = '0';
  883. propDefaults['baseline-shift'] = 'baseline';
  884. propDefaults['clip'] = 'auto';
  885. propDefaults['clip-path'] = 'none';
  886. propDefaults['clip-rule'] = 'nonzero';
  887. propDefaults['color'] = 'depends on user agent';
  888. propDefaults['color-interpolation'] = 'sRGB';
  889. propDefaults['color-interpolation-filters'] = 'linearRGB';
  890. propDefaults['color-profile'] = 'auto';
  891. propDefaults['color-rendering'] = 'auto';
  892. propDefaults['cursor'] = 'auto';
  893. propDefaults['direction'] = 'ltr';
  894. propDefaults['display'] = 'inline';
  895. propDefaults['dominant-baseline'] = 'auto';
  896. propDefaults['enable-background'] = 'accumulate';
  897. propDefaults['fill'] = 'black';
  898. propDefaults['fill-opacity'] = '1';
  899. propDefaults['fill-rule'] = 'nonzero';
  900. propDefaults['filter'] = 'none';
  901. propDefaults['flood-color'] = 'black';
  902. propDefaults['flood-opacity'] = '1';
  903. propDefaults['font'] = 'see individual properties';
  904. propDefaults['font-family'] = 'Arial';
  905. propDefaults['font-size'] = 'medium';
  906. propDefaults['font-size-adjust'] = 'none';
  907. propDefaults['font-stretch'] = 'normal';
  908. propDefaults['font-style'] = 'normal';
  909. propDefaults['font-variant'] = 'normal';
  910. propDefaults['font-weight'] = 'normal';
  911. propDefaults['glyph-orientation-horizontal'] = '0';
  912. propDefaults['glyph-orientation-vertical'] = 'auto';
  913. propDefaults['image-rendering'] = 'auto';
  914. propDefaults['kerning'] = 'auto';
  915. propDefaults['letter-spacing'] = 'normal';
  916. propDefaults['lighting-color'] = 'white';
  917. propDefaults['marker-end'] = 'none';
  918. propDefaults['marker-mid'] = 'none';
  919. propDefaults['marker-start'] = 'none';
  920. propDefaults['mask'] = 'none';
  921. propDefaults['opacity'] = '1';
  922. propDefaults['overflow'] = 'hidden';
  923. propDefaults['pointer-events'] = 'visiblePainted';
  924. propDefaults['shape-rendering'] = 'auto';
  925. propDefaults['stop-color'] = 'black';
  926. propDefaults['stop-opacity'] = '1';
  927. propDefaults['stroke'] = 'none';
  928. propDefaults['stroke-dasharray'] = 'none';
  929. propDefaults['stroke-dashoffset'] = '0';
  930. propDefaults['stroke-linecap'] = 'butt';
  931. propDefaults['stroke-linejoin'] = 'miter';
  932. propDefaults['stroke-miterlimit'] = '4';
  933. propDefaults['stroke-opacity'] = '1';
  934. propDefaults['stroke-width'] = '1';
  935. propDefaults['text-anchor'] = 'start';
  936. propDefaults['text-decoration'] = 'none';
  937. propDefaults['text-rendering'] = 'auto';
  938. propDefaults['unicode-bidi'] = 'normal';
  939. propDefaults['visibility'] = 'visible';
  940. propDefaults['word-spacing'] = 'normal';
  941. propDefaults['writing-mode'] = 'lr-tb';
  942.  
  943.  
  944. var colorList = {
  945.    nameArray : ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'grey', 'green', 'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen'],
  946.  
  947.    hexArray : ['#f0f8ff', '#faebd7', '#00ffff', '#7fffd4', '#f0ffff', '#f5f5dc', '#ffe4c4', '#000000', '#ffebcd', '#0000ff', '#8a2be2', '#a52a2a', '#deb887', '#5f9ea0', '#7fff00', '#d2691e', '#ff7f50', '#6495ed', '#fff8dc', '#dc143c', '#00ffff', '#00008b', '#008b8b', '#b8860b', '#a9a9a9', '#006400', '#a9a9a9', '#bdb76b', '#8b008b', '#556b2f', '#ff8c00', '#9932cc', '#8b0000', '#e9967a', '#8fbc8f', '#483d8b', '#2f4f4f', '#2f4f4f', '#00ced1', '#9400d3', '#ff1493', '#00bfff', '#696969', '#696969', '#1e90ff', '#b22222', '#fffaf0', '#228b22', '#ff00ff', '#dcdcdc', '#f8f8ff', '#ffd700', '#daa520', '#808080', '#808080', '#008000', '#adff2f', '#f0fff0', '#ff69b4', '#cd5c5c', '#4b0082', '#fffff0', '#f0e68c', '#e6e6fa', '#fff0f5', '#7cfc00', '#fffacd', '#add8e6', '#f08080', '#e0ffff', '#fafad2', '#d3d3d3', '#90ee90', '#d3d3d3', '#ffb6c1', '#ffa07a', '#20b2aa', '#87cefa', '#778899', '#778899', '#b0c4de', '#ffffe0', '#00ff00', '#32cd32', '#faf0e6', '#ff00ff', '#800000', '#66cdaa', '#0000cd', '#ba55d3', '#9370db', '#3cb371', '#7b68ee', '#00fa9a', '#48d1cc', '#c71585', '#191970', '#f5fffa', '#ffe4e1', '#ffe4b5', '#ffdead', '#000080', '#fdf5e6', '#808000', '#6b8e23', '#ffa500', '#ff4500', '#da70d6', '#eee8aa', '#98fb98', '#afeeee', '#db7093', '#ffefd5', '#ffdab9', '#cd853f', '#ffc0cb', '#dda0dd', '#b0e0e6', '#800080', '#ff0000', '#bc8f8f', '#4169e1', '#8b4513', '#fa8072', '#f4a460', '#2e8b57', '#fff5ee', '#a0522d', '#c0c0c0', '#87ceeb', '#6a5acd', '#708090', '#708090', '#fffafa', '#00ff7f', '#4682b4', '#d2b48c', '#008080', '#d8bfd8', '#ff6347', '#40e0d0', '#ee82ee', '#f5deb3', '#ffffff', '#f5f5f5', '#ffff00', '#9acd32'],
  948.  
  949.  
  950.    rgbArray : ['rgb(240, 248, 255)', 'rgb(250, 235, 215)', 'rgb(0, 255, 255)', 'rgb(127, 255, 212)', 'rgb(240, 255, 255)', 'rgb(245, 245, 220)', 'rgb(255, 228, 196)', 'rgb(0, 0, 0)', 'rgb(255, 235, 205)', 'rgb(0, 0, 255)', 'rgb(138, 43, 226)', 'rgb(165, 42, 42)', 'rgb(222, 184, 135)', 'rgb(95, 158, 160)', 'rgb(127, 255, 0)', 'rgb(210, 105, 30)', 'rgb(255, 127, 80)', 'rgb(100, 149, 237)', 'rgb(255, 248, 220)', 'rgb(220, 20, 60)', 'rgb(0, 255, 255)', 'rgb(0, 0, 139)', 'rgb(0, 139, 139)', 'rgb(184, 134, 11)', 'rgb(169, 169, 169)', 'rgb(0, 100, 0)', 'rgb(169, 169, 169)', 'rgb(189, 183, 107)', 'rgb(139, 0, 139)', 'rgb(85, 107, 47)', 'rgb(255, 140, 0)', 'rgb(153, 50, 204)', 'rgb(139, 0, 0)', 'rgb(233, 150, 122)', 'rgb(143, 188, 143)', 'rgb(72, 61, 139)', 'rgb(47, 79, 79)', 'rgb(47, 79, 79)', 'rgb(0, 206, 209)', 'rgb(148, 0, 211)', 'rgb(255, 20, 147)', 'rgb(0, 191, 255)', 'rgb(105, 105, 105)', 'rgb(105, 105, 105)', 'rgb(30, 144, 255)', 'rgb(178, 34, 34)', 'rgb(255, 250, 240)', 'rgb(34, 139, 34)', 'rgb(255, 0, 255)', 'rgb(220, 220, 220)', 'rgb(248, 248, 255)', 'rgb(255, 215, 0)', 'rgb(218, 165, 32)', 'rgb(128, 128, 128)', 'rgb(128, 128, 128)', 'rgb(0, 128, 0)', 'rgb(173, 255, 47)', 'rgb(240, 255, 240)', 'rgb(255, 105, 180)', 'rgb(205, 92, 92)', 'rgb(75, 0, 130)', 'rgb(255, 255, 240)', 'rgb(240, 230, 140)', 'rgb(230, 230, 250)', 'rgb(255, 240, 245)', 'rgb(124, 252, 0)', 'rgb(255, 250, 205)', 'rgb(173, 216, 230)', 'rgb(240, 128, 128)', 'rgb(224, 255, 255)', 'rgb(250, 250, 210)', 'rgb(211, 211, 211)', 'rgb(144, 238, 144)', 'rgb(211, 211, 211)', 'rgb(255, 182, 193)', 'rgb(255, 160, 122)', 'rgb(32, 178, 170)', 'rgb(135, 206, 250)', 'rgb(119, 136, 153)', 'rgb(119, 136, 153)', 'rgb(176, 196, 222)', 'rgb(255, 255, 224)', 'rgb(0, 255, 0)', 'rgb(50, 205, 50)', 'rgb(250, 240, 230)', 'rgb(255, 0, 255)', 'rgb(128, 0, 0)', 'rgb(102, 205, 170)', 'rgb(0, 0, 205)', 'rgb(186, 85, 211)', 'rgb(147, 112, 219)', 'rgb(60, 179, 113)', 'rgb(123, 104, 238)', 'rgb(0, 250, 154)', 'rgb(72, 209, 204)', 'rgb(199, 21, 133)', 'rgb(25, 25, 112)', 'rgb(245, 255, 250)', 'rgb(255, 228, 225)', 'rgb(255, 228, 181)', 'rgb(255, 222, 173)', 'rgb(0, 0, 128)', 'rgb(253, 245, 230)', 'rgb(128, 128, 0)', 'rgb(107, 142, 35)', 'rgb(255, 165, 0)', 'rgb(255, 69, 0)', 'rgb(218, 112, 214)', 'rgb(238, 232, 170)', 'rgb(152, 251, 152)', 'rgb(175, 238, 238)', 'rgb(219, 112, 147)', 'rgb(255, 239, 213)', 'rgb(255, 218, 185)', 'rgb(205, 133, 63)', 'rgb(255, 192, 203)', 'rgb(221, 160, 221)', 'rgb(176, 224, 230)', 'rgb(128, 0, 128)', 'rgb(255, 0, 0)', 'rgb(188, 143, 143)', 'rgb(65, 105, 225)', 'rgb(139, 69, 19)', 'rgb(250, 128, 114)', 'rgb(244, 164, 96)', 'rgb(46, 139, 87)', 'rgb(255, 245, 238)', 'rgb(160, 82, 45)', 'rgb(192, 192, 192)', 'rgb(135, 206, 235)', 'rgb(106, 90, 205)', 'rgb(112, 128, 144)', 'rgb(112, 128, 144)', 'rgb(255, 250, 250)', 'rgb(0, 255, 127)', 'rgb(70, 130, 180)', 'rgb(210, 180, 140)', 'rgb(0, 128, 128)', 'rgb(216, 191, 216)', 'rgb(255, 99, 71)', 'rgb(64, 224, 208)', 'rgb(238, 130, 238)', 'rgb(245, 222, 179)', 'rgb(255, 255, 255)', 'rgb(245, 245, 245)', 'rgb(255, 255, 0)', 'rgb(154, 205, 50)'],
  951.  
  952.    getHexByName : function( name )
  953.    {
  954.       for ( var i = 0, iLen = this.nameArray.length; iLen > i; i++ )
  955.       {
  956.          var eachItem = this.nameArray[i];
  957.          if ( name == eachItem )
  958.          {
  959.             return this.hexArray[i];
  960.          }
  961.       }
  962.    },
  963.  
  964.    getRgbByName : function( name )
  965.    {
  966.       for ( var i = 0, iLen = this.nameArray.length; iLen > i; i++ )
  967.       {
  968.          var eachItem = this.nameArray[i];
  969.          if ( name == eachItem )
  970.          {
  971.             return this.rgbArray[i];
  972.          }
  973.       }
  974.    },
  975.  
  976.    getNameByHex : function( hex )
  977.    {
  978.       for ( var i = 0, iLen = this.hexArray.length; iLen > i; i++ )
  979.       {
  980.          var eachItem = this.hexArray[i];
  981.          if ( hex == eachItem )
  982.          {
  983.             return this.nameArray[i];
  984.          }
  985.       }
  986.    },
  987.  
  988.    getRgbByHex : function( hex )
  989.    {
  990.       for ( var i = 0, iLen = this.hexArray.length; iLen > i; i++ )
  991.       {
  992.          var eachItem = this.hexArray[i];
  993.          if ( hex == eachItem )
  994.          {
  995.             return this.rgbArray[i];
  996.          }
  997.       }
  998.    },
  999.  
  1000.    getNameByRgb : function( rgb )
  1001.    {
  1002.       for ( var i = 0, iLen = this.rgbArray.length; iLen > i; i++ )
  1003.       {
  1004.          var eachItem = this.rgbArray[i];
  1005.          if ( rgb == eachItem )
  1006.          {
  1007.             return this.nameArray[i];
  1008.          }
  1009.       }
  1010.    },
  1011.  
  1012.    getHexByRgb : function( rgb )
  1013.    {
  1014.       for ( var i = 0, iLen = this.rgbArray.length; iLen > i; i++ )
  1015.       {
  1016.          var eachItem = this.rgbArray[i];
  1017.          if ( rgb == eachItem )
  1018.          {
  1019.             return this.hexArray[i];
  1020.          }
  1021.       }
  1022.    },
  1023.  
  1024.    normalizeHex : function( hex )
  1025.    {
  1026.       hex = hex.toLowerCase();
  1027.       if ( 4 == hex.length )
  1028.       {
  1029.          var hexSplit = hex.split('');
  1030.          hex = hexSplit[0] + hexSplit[1] + hexSplit[1] + hexSplit[2] + hexSplit[2] + hexSplit[3] + hexSplit[3];
  1031.       }
  1032.  
  1033.       return hex;
  1034.    },
  1035.  
  1036.    normalizeRgb : function( rgb )
  1037.    {
  1038.       var rgbSplit = this.splitRgb( rgb );
  1039.       rgb = 'rgb(' + rgbSplit.join(', ') +')';
  1040.  
  1041.       return rgb;
  1042.    },
  1043.  
  1044.    splitRgb : function( rgb )
  1045.    {
  1046.       rgb = rgb.replace(' ', '');
  1047.       rgb = rgb.replace('rgb(', '');
  1048.       rgb = rgb.replace(')', '');
  1049.       var rgbSplit = rgb.split(',');
  1050.  
  1051.       return rgbSplit;
  1052.    }
  1053. };
  1054.  
  1055. function GetElementByAtt( attName, attValue )
  1056. {
  1057.    var element = null;
  1058.    if ( 'id' == attName )
  1059.    {
  1060.       element = SVGDocument.getElementById( attValue );
  1061.    }
  1062.  
  1063.    if ( !element )
  1064.    {
  1065.       var allElements = SVGDocument.getElementsByTagNameNS(svgns, '*');
  1066.       for ( var e = 0, eLen = allElements.length; eLen > e; e++ )
  1067.       {
  1068.          var eachElement = allElements.item(e);
  1069.          var value = eachElement.getAttributeNS(null, attName);
  1070.          if ( attValue == value )
  1071.          {
  1072.             element = eachElement;
  1073.             break;
  1074.          }
  1075.       }
  1076.    }
  1077.  
  1078.    return element;
  1079. }
  1080.